package br.com.alugargaragem.domain.login.model;

import javax.persistence.Embedded;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import br.com.alugargaragem.domain.vo.Email;
import br.com.alugargaragem.domain.vo.Password;
import br.com.lambdacore.domain.model.EntityModel;
import br.com.lambdacore.lang.EqualsBuilder;
import br.com.lambdacore.lang.HashCodeBuilder;
import br.com.lambdacore.lang.ToStringBuilder;
import br.com.lambdacore.lang.annotation.EqualsHashCode;
import br.com.lambdacore.lang.annotation.ToString;

@NamedQueries({
		@NamedQuery(name = "findAll", query = "SELECT l FROM Login l"),
		@NamedQuery(name = "findByEmail", query = "SELECT l FROM Login l WHERE l.email = :email"),
		@NamedQuery(name = "findByEmailPassword", query = "SELECT l FROM Login l WHERE l.email = :email and password = :password")
})
@Entity
public class Login implements EntityModel<LoginId> {

	private static final long serialVersionUID = 1L;

	@ToString
	@EqualsHashCode
	@Embedded
	private Email email;

	@Embedded
	private Password password;

	@EmbeddedId
	private LoginId id;

	public Login() {
	}

	public Login(LoginId id) {
		this.setId(id);
	}

	@Override
	public boolean equals(Object other) {
		return EqualsBuilder.newInstance(this).equals(other);
	}

	public Email getEmail() {
		return this.email;
	}

	public LoginId getId() {
		return this.id;
	}

	public Password getPassword() {
		return this.password;
	}

	@Override
	public int hashCode() {
		return HashCodeBuilder.newInstance(this).hashCode();
	}

	public void setEmail(Email login) {
		this.email = login;
	}

	public Login setId(LoginId id) {
		this.id = id;
		return this;
	}

	public void setPassword(Password password) {
		this.password = password;
	}

	@Override
	public String toString() {
		return ToStringBuilder.newInstance(this).toString();
	}

}
